<template>
	<view class="content">
		<u-navbar title="收货地址管理"  :autoBack="true">
        </u-navbar>
		<view class="info">

			<view class="c1">收货人</view>
			<view class="c2">
				<u--input v-model='info.delivery_name' placeholder="请输入" :customStyle="{padding: '0 32rpx'}">
				</u--input>
			</view>

			<view class="c1">手机号</view>
			<view class="c2">
				<u--input v-model='info.delivery_phone' placeholder="请输入" :customStyle="{padding: '0 32rpx'}">
				</u--input>
			</view>

			<view class="c1">所在地区</view>
			<view class="c2">
				<u--input v-model='info.delivery_district' placeholder="请选择" :customStyle="{padding: '0 32rpx'}"
					suffixIcon="arrow-down" suffixIconStyle="color: #7D8592" readonly>
				</u--input>
				<view class="on_in" @click="addressShow = true"></view>
			</view>

			<view class="c1">详细地址</view>
			<view class="c2">
				<u--input v-model='info.delivery_address' placeholder="请输入" :customStyle="{padding: '0 32rpx'}">
				</u--input>
			</view>

		</view>

		<view class="but">
			<view class="s2" @click="onSend()">
				<text>保 存</text>
			</view>
		</view>

		<address-picker :show="addressShow" closeOnClickOverlay @confirm='confirmAddress' @cancel='addressShow=false'
			@close='addressShow = false' :address-data="addressData" :indexs="indexs" :areaId="areaId"
			:type="type"></address-picker>

	</view>
</template>

<script>
	import conf from '@/common/config.js';
	export default {
		data() {
			return {
				info: {},
				addressShow: false,
				areaId: [1, 110000, 110101],
				addressData: ['北京市', '北京市', '东城区'],
				type: 3, //1-省，2-省市，3-省市区
				formType: '',
				indexs: []
			};
		},
		onLoad({
			formType
		}) {
			this.formType = formType
		},
		onShow() {
			this.getInfo();
		},
		methods: {
			getInfo() {
				this.$API.getUserAddress().then(res => {
					this.info = res.data;
				})
			},
			confirmAddress(val) {
				console.log(val);
				this.info.delivery_district = val.value.join('')
				this.addressShow = false
			},
			onClose() {
				this.addressShow = false;
			},
			onSend() {
				this.$API.sendUserAddress(this.info).then(res => {
					uni.showModal({
						content: '保存成功',
						showCancel: false,
						success: () => {
							console.log(this.formType);
							if (this.formType) {
								uni.$emit('updateAddress', {
									take_over_name: this.info.delivery_district,
									index: +(this.formType)
								})
								uni.navigateBack()
							} else {
								uni.redirectTo({
									url: '/pages/my/index',
								})
							}

						}
					})
				})
			}
		}
	}
</script>

<style lang="scss">
	.content {
		width: 670rpx;
		margin: 0 auto;
	}

	.info {
		width: 566rpx;
		padding: 0 52rpx 52rpx 52rpx;
		margin: 52rpx auto;
		background-color: #fff;
		border-radius: 48rpx;
		@include flex(column);

		.avatar {
			image {
				width: 120rpx;
				height: 120rpx;
				border-radius: 50%;
			}
		}

		.c1 {
			height: 28rpx;
			font-size: 28rpx;
			font-family: Alibaba PuHuiTi 2.0, Alibaba PuHuiTi 20;
			font-weight: 400;
			color: #7D8592;
			line-height: 28rpx;
			margin-top: 56rpx;
		}

		.c2 {
			width: 566rpx;
			margin-top: 40rpx;
			position: relative;

			/deep/ .u-input {
				height: 98rpx;
				border-radius: 28rpx;
			}

			.on_in {
				position: absolute;
				inset: 0;
			}
		}

		.qrcode {
			image {
				width: 128rpx;
				height: 128rpx;
				margin-top: 24rpx;
			}
		}

	}

	.but {
		@include flex;
		margin-top: 60rpx;
		margin-bottom: 60rpx;

		.s2 {
			width: 290rpx;
			height: 96rpx;
			background: #7677EB;
			box-shadow: 0 12rpx 24rpx 0 rgba(63, 140, 255, 0.2637);
			border-radius: 28rpx;
			margin: 0 auto;
			text-align: center;

			text {
				font-size: 30rpx;
				font-family: Alibaba PuHuiTi 2.0, Alibaba PuHuiTi 20;
				font-weight: 400;
				color: #FFFFFF;
				line-height: 96rpx;
			}
		}
	}
</style>